package cn.java.Concurrency.completionService;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 小石潭记
 * @date 2021/12/19 19:37
 * @Description: ${todo}
 */
public class Run {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        ExecutorCompletionService<Object> completionService = new ExecutorCompletionService<>(executorService);
        for (int i = 0; i < 1; i++) {
            completionService.submit(new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    Thread.sleep(3000);
                    System.out.println("3秒过后了");
                    return "小石潭记 3s";
                }
            });
        }
        for (int i = 0; i < 1; i++) {
            System.out.println(completionService.poll());
        }
    }
}
